#import "RequestCreator.h"


@implementation RequestCreator

+(NSString *) createGetCity : (NSString *) province{
	NSString *request = @"<soap:Envelope xmlns:xsi='http://www.w3.org/XMLSchema-instance' xmlns:xsd='http://www.w3.org/2001/XMLSchema' xmlns:soap='http://schemas.xmlsoap.org/soap/envelope/'>";
	request = [request stringByAppendingFormat: @"<soap:Body><getSupportCityString xmlns='http://WebXml.com.cn/'><theRegionCode>%@</theRegionCode></getSupportCityString></soap:Body>", province];
	request = [request stringByAppendingString: @"</soap:Envelope>"];
	return request; 
}

+(NSString *) createGetWeather : (NSString *) city{
	NSString *request = @"<soap:Envelope xmlns:xsi='http://www.w3.org/XMLSchema-instance' xmlns:xsd='http://www.w3.org/2001/XMLSchema' xmlns:soap='http://schemas.xmlsoap.org/soap/envelope/'>";
	request = [request stringByAppendingFormat: @"<soap:Body><getWeather xmlns='http://WebXml.com.cn/'><theCityCode>%@</theCityCode></getWeather></soap:Body>", city];
	request = [request stringByAppendingString: @"</soap:Envelope>"];
	return request; 
}

+(void) invokeWs: (NSString *) soapAction envelope: (NSString *) envelope delegate : (id) delegate{
	NSURL *url = [[NSURL alloc] initWithString: @"http://webservice.webxml.com.cn/WebServices/WeatherWS.asmx"];
	NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL: url];
	[url release];
	
	[request setHTTPMethod: @"POST"];
	[request setHTTPBody: [envelope dataUsingEncoding: NSUTF8StringEncoding]];
	
	[request setValue: @"webservice.webxml.com.cn" forHTTPHeaderField: @"Host"];
	[request setValue: @"text/xml; charset=UTF-8" forHTTPHeaderField: @"Content-type"];
	[request setValue: soapAction forHTTPHeaderField:@"SOAPAction"];
	
	NSURLConnection *connection = [[NSURLConnection alloc] initWithRequest: request delegate: delegate];
	[connection release];
	[request release];
}
@end
